package com.sports.common.config;

import com.sports.common.exception.AppExceptionHandler;
import com.sports.domain.ResultDTO;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.InternalAuthenticationServiceException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.ServletException;

@RestControllerAdvice
public class SportsExceptionHander extends AppExceptionHandler {
    public SportsExceptionHander() {
        super("Sports");
    }

    @ExceptionHandler({ServletException.class})
    public ResultDTO servletException(ServletException e) {
        return ResultDTO.error("sys." + "Sports" + ".404", e.getMessage());
    }

    @ExceptionHandler({InternalAuthenticationServiceException.class})
    public ResultDTO internalAuthenticationServiceException(InternalAuthenticationServiceException e) {
        return ResultDTO.error("sys." + "Sports" + ".500", e.getMessage());
    }

    @ExceptionHandler({BadCredentialsException.class})
    public ResultDTO badCredentialsException(BadCredentialsException e) {
        return ResultDTO.error("sys." + "Sports" + ".500", "亲！密码错误");
    }
}